package za.co.felixsol.sf.gcode.instructions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public abstract class Instruction {

	private List<InstructionParameter> parameters;

	public abstract String getGCode();

	public abstract String getDescription();

	public Instruction() {
		parameters = new ArrayList<InstructionParameter>();
	}

	public List<String> getParameterNames() {
		List<String> result = new ArrayList<String>();
		if (parameters != null) {
			for (InstructionParameter parameter : parameters) {
				result.add(parameter.getName());
			}
		}
		return result;
	}

	public List<InstructionParameter> getParameters() {
		return parameters;
	}

	public InstructionParameter getParameter(String name) {
		if (parameters != null) {
			for (InstructionParameter parameter : parameters) {
				if (name.equals(parameter.getName())) {
					return parameter;
				}
			}
		}
		return null;
	}
	
	public InstructionParameter createParameter(String name) {
		return createParameter(name, 0, null);
	}

	public InstructionParameter createParameter(String name, Object value) {
		return createParameter(name, 0, value);
	}

	public InstructionParameter createParameter(String name, Integer sequence, Object value) {
		InstructionParameter result = new InstructionParameter(name, sequence, value);
		parameters.add(result);
		return result;
	}

}
